#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

#define MY_FILE "./test_file"

int main(void) 
{
    int ret;

    /* 检查文件是否存在 */
    ret = access(MY_FILE, F_OK);
    if (-1 == ret) {
        printf("%:file does not exist.\n", MY_FILE);
        exit(-1);
    }

    /* 检查文件权限 */
    ret = access(MY_FILE, R_OK);
    if (!ret) {
        printf("Read permission: YES\n");
    } else {
        printf("Read permission: NO\n");
    }
    ret = access(MY_FILE, W_OK);
    if (!ret) {
        printf("Write permission: YES\n");
    } else {
        printf("Write permission: NO\n");
    }
    ret = access(MY_FILE, X_OK);
    if (!ret) {
        printf("Execution permission: YES\n");
    } else {
        printf("Execution permission: NO\n");
    }

    exit(0);
}